473,466 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to clear the combo box values using javascript..?

nirmalsingh
218 New Member
my combo box id is combo1, i want to clear the values that are loaded in combo box from database, plz help me with sample code..
Jan 4 '07 #1
7 27553
b1randon
171 Recognized Expert New Member
my combo box id is combo1, i want to clear the values that are loaded in combo box from database, plz help me with sample code..
Post some code that we can help you with...
Jan 4 '07 #2
nirmalsingh
218 New Member
//my coding...
var strDetails;
var intLoop;
var strArrRow = new Array();
strDetails=xmlHttp.statusText;//records to load combo..
strArrRow =strDetails.split('|');
var x=document.getElementById("combo1");
for (intLoop=0;intLoop<strArrRow.length-1;intLoop++)
{
var y=document.createElement('option');
y.text=strArrRow[intLoop]
try
{
x.add(y, null);
}
catch(ex)
{
x.add(y);
}
}
Jan 5 '07 #3
r035198x
13,262 MVP
//my coding...
var strDetails;
var intLoop;
var strArrRow = new Array();
strDetails=xmlHttp.statusText;//records to load combo..
strArrRow =strDetails.split('|');
var x=document.getElementById("combo1");
for (intLoop=0;intLoop<strArrRow.length-1;intLoop++)
{
var y=document.createElement('option');
y.text=strArrRow[intLoop]
try
{
x.add(y, null);
}
catch(ex)
{
x.add(y);
}
}
I'm a bit confused here. Do you want to delete values from the database or do you want to clear options from a select box?
Jan 5 '07 #4
nirmalsingh
218 New Member
sorry to make u confused sir, i want to clear the options from the select box. not from database.
Jan 5 '07 #5
r035198x
13,262 MVP
sorry to make u confused sir, i want to clear the options from the select box. not from database.
Well the general rule is if you have a select by the name box, then

To clear all options of box just do
box.options.length = 0;
Jan 5 '07 #6
b1randon
171 Recognized Expert New Member
Well the general rule is if you have a select by the name box, then

To clear all options of box just do
box.options.length = 0;
This is by far the best way to remove the options. If you try to remove them one by one in a loop you won't be able to remove the last option. I lost a good bit of hair before realizing that options.length=0; is all I needed :/
Jan 5 '07 #7
r035198x
13,262 MVP
This is by far the best way to remove the options. If you try to remove them one by one in a loop you won't be able to remove the last option. I lost a good bit of hair before realizing that options.length=0; is all I needed :/
I hope the hair grew back on.
Jan 6 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mr_burns | last post by:
hi, using javascript, how do i select an option in a combo box? i have tried looking on the internet but dont really know what i should be searching for. what i want to happen is that when a...
2
by: Stephen Miller | last post by:
I have a page with many, dynamically generated combo boxes and I want to check all of them, before I add a unique value to specific combo. What would be the best way to work through the document...
1
by: SAN CAZIANO | last post by:
how can clear an html SELECT and next insert in it all the elements of an array () I try this but seems doesn't works. function ComboAddArrayValueWithLabel(combo,ArrayLabel,ArrayValue) { ...
5
by: Harry Haller | last post by:
<select name="cboPlaces" id="cboPlaces"> <option value="3">Countryside</option> <option value="4">Forest</option> <option value="5">Mountain</option> <option value="6">Desert</option> <option...
2
by: Eric Layman | last post by:
Hi, I have a radio button and a combo box. Upon changing a value for radio button, the combo box values will be dynamically updated. I have an idea on how to go abt doing it but Im stuck...
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.